package com.jinyi.wwdeng.utils.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import com.jinyi.base.utils.img.ImageUtil
import com.jinyi.wwdeng.R
import com.jinyi.wwdeng.databinding.DialogBindCardOtherBinding
import com.jinyi.wwdeng.utils.event.TrackEventType
import com.jinyi.wwdeng.utils.event.TrackEventUtils
import org.json.JSONObject

/**
 * Author : wwdeng
 * Date : 2023/8/1 15:44
 * <p>
 * 每天进步一点点
 * <p>
 * Desc : 绑卡换卡dialog
 */
class BindCardOtherDialog: ProDialog {
    private lateinit var binding: DialogBindCardOtherBinding
    private var mCallback: IDialogCallback? = null

    //事件备注
    private var eventRemark = ""

    constructor(context: Context?) : super(context) {}
    constructor(context: Context?, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    constructor(context: Context?, remark: String,callback: IDialogCallback?) : super(context) {
        mCallback = callback
        eventRemark = remark
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogBindCardOtherBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
    }

    override fun initListener() {
        setOnClickListener(R.id.ivClose) //关闭
        setOnClickListener(R.id.btnLeft) //两个按钮 左侧按钮
        setOnClickListener(R.id.btnRight) //两个按钮 又侧按钮
    }

    override fun initData() {
    }

    override fun onViewClick(v: View?) {
        dismiss()
        when(v!!.id){
            R.id.ivClose,
            R.id.btnLeft -> {
                TrackEventUtils.logEvent(TrackEventType.CLICK.CLICK_USER_ACCOUNT_BIND_OTHER_CANCEL,eventRemark)
            }
            else -> {
                TrackEventUtils.logEvent(TrackEventType.CLICK.CLICK_USER_ACCOUNT_BIND_OTHER_CONFIRM,eventRemark)
            }
        }
        if(mCallback != null){
            mCallback!!.onClick(v)
        }
    }

    /**
     * 设置账户信息
     */
    fun setBindAccountInfo(info: JSONObject){
        binding.accountLayout.tvIndex.text = String.format(context.getString(R.string.portefeuille_mobile),1)
        ImageUtil.getInstance().loadImage(context,binding.accountLayout.bindedLayout.imgLogo,info.optString("logo"),R.mipmap.pic_holder_icon)
        binding.accountLayout.bindedLayout.tvAccountName.text = info.optString("desc")
        binding.accountLayout.bindedLayout.tvAccountMobile.text = info.optString("walletMobile")
        binding.accountLayout.bindedLayout.btnDelete.visibility = View.INVISIBLE
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        TrackEventUtils.logEvent(TrackEventType.DIALOG.DIALOG_USER_ACCOUNT_BIND_OTHER_TIPS_SHOW,eventRemark)
    }

    override fun dismiss() {
        super.dismiss()
        TrackEventUtils.logEvent(TrackEventType.DIALOG.DIALOG_USER_ACCOUNT_BIND_OTHER_TIPS_DISMISS,eventRemark)
    }
}